package com.czy.owner.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.entity.IllegalQueryDetailModel;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;

/**
 * Created by wangyang on 2016/12/10.
 */
public class IllegalQueryDetailAdapter extends RecyclerArrayAdapter<IllegalQueryDetailModel> {
    private Context ctx;

    public IllegalQueryDetailAdapter(Context context) {
        super(context);
        this.ctx = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new IllegalQueryDetailViewHolder(parent, ctx);
    }

    class IllegalQueryDetailViewHolder extends BaseViewHolder<IllegalQueryDetailModel> {
        private TextView tv_fa_fen;
        private TextView tv_fa_money;
        private ImageView image_icon_right;
        private RelativeLayout rl_show_detail;
        private LinearLayout ll_illegal_detail;
        private TextView tv_illegal_time;
        private TextView tv_illegal_local;
        private TextView tv_illegal_type;
        private Context ctx;


        public IllegalQueryDetailViewHolder(ViewGroup parent, Context ctx) {
            super(parent, R.layout.item_illegal_query_detail);
            tv_fa_fen = $(R.id.tv_fa_fen);
            tv_fa_money = $(R.id.tv_fa_money);
            image_icon_right = $(R.id.image_icon_right);
            rl_show_detail = $(R.id.rl_show_detail);
            ll_illegal_detail = $(R.id.ll_illegal_detail);
            tv_illegal_time = $(R.id.tv_illegal_time);
            tv_illegal_local = $(R.id.tv_illegal_local);
            tv_illegal_type = $(R.id.tv_illegal_type);
            this.ctx = ctx;
        }

        @Override
        public void setData(final IllegalQueryDetailModel model) {
            tv_fa_fen.setText(model.getScore() + "");
            tv_fa_money.setText(model.getPrice() + "");
            tv_illegal_time.setText("时间: " + model.getTime());
            tv_illegal_local.setText("地点: " + model.getAddress());
            tv_illegal_type.setText("违章: " + model.getContent());

            rl_show_detail.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (ll_illegal_detail.getVisibility() == View.GONE) {
                        ll_illegal_detail.setVisibility(View.VISIBLE);
                        image_icon_right.setImageResource(R.mipmap.illegal_xia);
                    } else {
                        ll_illegal_detail.setVisibility(View.GONE);
                        image_icon_right.setImageResource(R.mipmap.icon_jinru);
                    }

                }
            });

        }
    }
}
